package net.tngou.crawler.dao;

import java.util.List;
import java.util.Map;

import net.tngou.crawler.enums.StateEnum;
import net.tngou.crawler.jdbc.QueryHelper;
import net.tngou.crawler.pojo.Data;

public class DataDao extends BaseDao {

	public List<Map<String, Object>> list(int page,int count,int state) {
		String sql="SELECT tgcrawler_data.* ,tgcrawler_urldata.weburl ,tgcrawler_urldata.url,tgcrawler_urldata.state ,tgcrawler_urldata.id as uid FROM `tgcrawler_urldata` LEFT JOIN  `tgcrawler_data`  ON tgcrawler_data.urldata=tgcrawler_urldata.id WHERE tgcrawler_urldata.state=? ORDER BY id DESC";
		List<Map<String, Object>> list = QueryHelper.query_page(sql, page, count,state);
		return list;
	}
	
	public int total(int state) {
		String sql="SELECT COUNT(*) FROM `tgcrawler_urldata` WHERE tgcrawler_urldata.state=?";
		return (int) QueryHelper.stat(sql,state);
	}
	
	public List<Data> list(int page,int count) {
		String sql="SELECT tgcrawler_data.* ,tgcrawler_urldata.weburl ,tgcrawler_urldata.url,tgcrawler_urldata.state FROM `tgcrawler_data` ,`tgcrawler_urldata` WHERE tgcrawler_data.urldata=tgcrawler_urldata.id AND tgcrawler_urldata.state=? ORDER BY id DESC";
		return QueryHelper.query_slice(Data.class, sql, page, count, StateEnum.爬取完成.ordinal());
	}
	
	public int totalstate(String equal,int state) {
		String sql ="SELECT COUNT(*) FROM `tgcrawler_urldata` ,`tgcrawler_data` WHERE `tgcrawler_data`.`urldata`=`tgcrawler_urldata`.`id` AND `tgcrawler_data`.`equal`=? AND `tgcrawler_urldata`.`state`=?";
		return (int) QueryHelper.stat(sql, equal,state);
	}
	
	public int getTotal(String md16,long weburl) {
		String sql="SELECT COUNT(*) FROM `tgcrawler_urldata`,`tgcrawler_data` WHERE tgcrawler_data.urldata=tgcrawler_urldata.id AND tgcrawler_data.md16=? AND tgcrawler_urldata.weburl=?";
		return (int)QueryHelper.stat(sql, md16,weburl);
	}
	
	
}
